package com.quanyan.pay.web;

import com.quanyan.api.APIRequest;
import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.encrypt.CustomCodec;
import com.quanyan.common.validation.base.Insert;
import com.quanyan.common.validation.base.Query;
import com.quanyan.common.validation.base.Update;
import com.quanyan.pay.entity.AlipayAccount;
import com.quanyan.pay.entity.WeichatAccount;
import com.quanyan.pay.service.AccountService;
import com.quanyan.pay.web.request.ReqAlipayAccount;
import com.quanyan.pay.web.request.ReqWeichatAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author songzj
 * @date 16/5/30-18:37
 */
@RestController
@RequestMapping("/account")
public class AccountController {


    @Autowired
    private AccountService accountService;

    @RequestMapping("/aliPay/save")
    public APIResponse<AlipayAccount> saveAliPay(@Validated(Insert.class) APIRequest<ReqAlipayAccount> reqAlipayAccount, BindingResult result) {
        return this.accountService.insertOrUpdateAlipayAccount(reqAlipayAccount);
    }

    @RequestMapping("/aliPay/update")
    public APIResponse<AlipayAccount> updateAliPay(@Validated(Update.class) APIRequest<ReqAlipayAccount> reqAlipayAccount, BindingResult result) {
        return this.accountService.insertOrUpdateAlipayAccount(reqAlipayAccount);
    }

    @RequestMapping("/aliPay/query")
    @CustomCodec(excludes = {"privateKey", "publicKey", "aliKey"})
    public APIResponse<PageObj<List<AlipayAccount>>> queryAliPay(@Validated(Query.class) APIRequest<ReqAlipayAccount> reqAlipayAccount, BindingResult result) {
        return this.accountService.selectAlipayAccountListByProperty(reqAlipayAccount);
    }

    @RequestMapping("/aliPay/get")
    public APIResponse<AlipayAccount> getAliPay(@Validated(Query.class) APIRequest<ReqAlipayAccount> reqAlipayAccount, BindingResult result) {
        return this.accountService.selectAlipayAccountByProperty(reqAlipayAccount);
    }


    @RequestMapping("/weiChat/save")
    public APIResponse<WeichatAccount> saveWeiChat(@Validated(Insert.class) APIRequest<ReqWeichatAccount> reqWeichatAccount, BindingResult result) {
        return this.accountService.insertOrUpdateWeichatAccount(reqWeichatAccount);
    }

    @RequestMapping("/weiChat/update")
    public APIResponse<WeichatAccount> updateWeiChat(@Validated(Update.class) APIRequest<ReqWeichatAccount> reqWeichatAccount, BindingResult result) {
        return this.accountService.insertOrUpdateWeichatAccount(reqWeichatAccount);
    }

    @RequestMapping("/weiChat/query")
    @CustomCodec(excludes = {"wxKey", "securityKey", "certPasswd"})
    public APIResponse<PageObj<List<WeichatAccount>>> queryWeiChat(@Validated(Query.class) APIRequest<ReqWeichatAccount> reqWeichatAccount, BindingResult result) {
        return this.accountService.selectWeichatAccountListByProperty(reqWeichatAccount);
    }

    @RequestMapping("/weiChat/get")
    public APIResponse<WeichatAccount> getWeiChat(@Validated(Query.class) APIRequest<ReqWeichatAccount> reqWeichatAccount, BindingResult result) {
        return this.accountService.selectWeichatAccountByProperty(reqWeichatAccount);
    }

}
